<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>  

<script type="text/javascript">
    
    $(document).ready(function(){
        
    });
    
    function supprimerBase(baseId){
        $("#modalBase").modal("show");
        
        $(".modal-body").html("Supprimer toutes les données de la base (utilisateurs, notes, enseignants, élèves, etc...) ?");
        
        $("#btnAnnuler").click(function(){
           $("#modalBase").modal("hide");
        });
        $("#btnValider").click(function(){
            location = '<c:url value="base.delete?baseid=" />' + baseId;
        });
    }
    
</script>

<a href="<c:url value="base.create" />">Créer une nouvelle base</a>
<table class="table table-striped">
    <thead>
    <tr>
        <td>ID</td>
        <td>Année</td>
        <td>Etablissement</td>
        <td>Créee le</td>
        <td>Fermée le</td>
        <td>Administrateur</td>
        <td>
            
        </td>
    </tr>
    </thead>
    <tbody>
        <c:forEach items="${bases}" var="base">
        <tr>
            <td>${base.id}</td>
            <td>${base.annee}</td>
            <td><a href="etablissement.edit?etablissementid=${base.etablissement.id}">${base.etablissement.uai} ${base.etablissement.nom}</a></td>
            <td><fmt:formatDate pattern="dd/MM/yyyy" value="${base.dateCreation}" /></td>
            <td><fmt:formatDate pattern="dd/MM/yyyy" value="${base.dateFermeture}" /></td>
            <td>
                ${base.administrateur.nom} (${base.administrateur.login})
            </td>
            <td class="buttons">
                <a href="<c:url value="base.edit?baseid=${base.id}" />">Modifier</a>
                <a href="javascript:supprimerBase(${base.id})">Supprimer</a>
            </td>
        </tr>
        </c:forEach>
    </tbody>
</table>

<c:set var="modalId" value="modalBase" scope="request" />
<c:set var="modalTitle" value="Supprimer la base" scope="request" />
<c:set var="modalBoutonValider" value="Supprimer la base" scope="request" />
<c:set var="modalBoutonAnnuler" value="Annuler" scope="request" />
<jsp:include page="../../components/modal.jsp" />